package com.example.demo.service.impl;

import com.example.demo.entity.Record;
import com.example.demo.entity.RecordExample;
import com.example.demo.entity.SysUserExample;
import com.example.demo.mapper.RecordMapper;
import com.example.demo.service.Recordservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Recordservicelimp implements Recordservice {
    @Autowired
    RecordMapper map;
    @Override
    public int deleteByPrimaryKey(int id) {
        return 0;
    }

    @Override
    public int insert(Record record) {
        return 0;
    }

    @Override
    public Record selectByPrimaryKey(int id) {
        return null;
    }

    @Override
    public int updateByPrimaryKey(Record record) {
        return 0;
    }

    @Override
    public List<Record> selectByExample(RecordExample recordExample) {
        return map.selectByExample(recordExample);
    }

    @Autowired
    RecordMapper recordMapper;


    public List<Record> selectByExample(SysUserExample sysUserExample) {
        return recordMapper.selectByExample(sysUserExample);
    }

    @Override
    public void add(Record record) {
        record.setSex("男");
        record.setStoptime("至今");
        recordMapper.add(record);
    }

    @Override
    public Record update() {
        Record record = new Record();
        RecordExample recordExample = new RecordExample();
        recordExample.createCriteria().andStoptimeEqualTo("至今");
        List<Record> records = recordMapper.selectByExample(recordExample);
        String starttime = records.get(0).getStarttime();
        System.out.println(starttime);
        //把添加的开始时间获取出来转换为时间格式，，减去开始时间。得到时间
//       Date date = new SimpleDateFormat("yyyy-MM-dd").parse(records.get(0).getStarttime());
//
//        String now = new SimpleDateFormat("yyyy年MM月dd日").format(date);
        //然后再获取当前时间
 //       SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
//        record.setStoptime(df-now);
        record.setSum("60");
        recordMapper.update(record);
        RecordExample recordExamples = new RecordExample();
        recordExamples.createCriteria().andStarttimeEqualTo(starttime);
        List<Record> recordse = recordMapper.selectByExample(recordExample);
        System.out.println();
        return recordse.get(0);
    }

    //查询记录
    @Override
    public List<Record> getrecord() {
        RecordExample recordExample = new RecordExample();
        return recordMapper.selectByExample(recordExample);
    }
}
